package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ReportRuleTask;
import com.ruoyi.system.service.IReportRuleTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 报告任务规则Controller
 * 
 * @author ruoyi
 * @date 2021-09-23
 */
@RestController
@RequestMapping("/system/task")
public class ReportRuleTaskController extends BaseController
{
    @Autowired
    private IReportRuleTaskService reportRuleTaskService;

    /**
     * 查询报告任务规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReportRuleTask reportRuleTask)
    {
        startPage();
        List<ReportRuleTask> list = reportRuleTaskService.selectReportRuleTaskList(reportRuleTask);
        return getDataTable(list);
    }

    /**
     * 导出报告任务规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:task:export')")
    @Log(title = "报告任务规则", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ReportRuleTask reportRuleTask)
    {
        List<ReportRuleTask> list = reportRuleTaskService.selectReportRuleTaskList(reportRuleTask);
        ExcelUtil<ReportRuleTask> util = new ExcelUtil<ReportRuleTask>(ReportRuleTask.class);
        return util.exportExcel(list, "报告任务规则数据");
    }

    /**
     * 获取报告任务规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:task:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(reportRuleTaskService.selectReportRuleTaskById(id));
    }

    /**
     * 新增报告任务规则
     */
    @PreAuthorize("@ss.hasPermi('system:task:add')")
    @Log(title = "报告任务规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReportRuleTask reportRuleTask)
    {
        return toAjax(reportRuleTaskService.insertReportRuleTask(reportRuleTask));
    }

    /**
     * 修改报告任务规则
     */
    @PreAuthorize("@ss.hasPermi('system:task:edit')")
    @Log(title = "报告任务规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReportRuleTask reportRuleTask)
    {
        return toAjax(reportRuleTaskService.updateReportRuleTask(reportRuleTask));
    }



    /**
     * 新增报告任务规则
     */
    @PreAuthorize("@ss.hasPermi('system:task:add')")
    @Log(title = "报告任务规则", businessType = BusinessType.INSERT)
    @PostMapping("/addReportTask")
    public AjaxResult addReportTask(@RequestBody ReportRuleTask reportRuleTask)
    {
        return toAjax(reportRuleTaskService.insertReportRuleTask(reportRuleTask));
    }

    /**
     * 修改报告任务规则
     */
    @PreAuthorize("@ss.hasPermi('system:task:edit')")
    @Log(title = "报告任务规则", businessType = BusinessType.UPDATE)
    @PutMapping("/updateReportTask")
    public AjaxResult updateReportTask(@RequestBody ReportRuleTask reportRuleTask)
    {
        return toAjax(reportRuleTaskService.updateReportRuleTask(reportRuleTask));
    }


    /**
     * 查询报告任务规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:task:list')")
    @GetMapping("/listReportTask")
    public TableDataInfo listReportTask(ReportRuleTask reportRuleTask)
    {
        startPage();
        List<ReportRuleTask> list = reportRuleTaskService.selectReportRuleTaskList(reportRuleTask);
        return getDataTable(list);
    }





    /**
     * 删除报告任务规则
     */
    @PreAuthorize("@ss.hasPermi('system:task:remove')")
    @Log(title = "报告任务规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(reportRuleTaskService.deleteReportRuleTaskByIds(ids));
    }
}
